//
//  YKConst.h
//  YKOCExection
//
//  Created by edward on 2020/5/26.
//  Copyright © 2020 edward. All rights reserved.
//


#ifndef YKConst_h
#define YKConst_h

//#import "Base.h"

/*** 沙盒 ***/
#define YKHomePath        NSHomeDirectory()
#define YKTempPath        NSTemporaryDirectory()
#define YKDocumentPath    [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]

/*** 日志 ***/
#ifdef DEBUG // 调试
#define YKLog(...) NSLog(@"🌧 %s 第%d行 %@",__func__,__LINE__,[NSString stringWithFormat:__VA_ARGS__])
#else // 发布
#define YKLog(...)
#endif


//弱引用&强引用
#define kWeakSelf(type)  __weak typeof(type) weak##type = type;
#define kStrongSelf(type)  __strong typeof(type) type = weak##type;

/*** 颜色 ***/
#define YKRGBColor(r,g,b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]

/*** UserDefaults ***/
#define YKSetUserDefault(key,value) [[NSUserDefaults standardUserDefaults] setObject:(value) forKey:(key)]
#define YKGetUserDefault(key) [[NSUserDefaults standardUserDefaults] objectForKey:(key)]

/*** KeyedArchive ***/
#define YKDocumentFilePath(name) [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.data",(name)]]
#define YKCacheFilePath(name) [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.data",(name)]]
#define YKKeyedArchive(fileName,obj) [NSKeyedArchiver archiveRootObject:(obj) toFile:YKDocumentFilePath(fileName)]
#define YKKeyedUnArchive(fileName) [NSKeyedUnarchiver unarchiveObjectWithFile:YKDocumentFilePath(fileName)]
#define YKKeyedArchiveFileDelete(filename) {\
NSFileManager *defaultManager = [NSFileManager defaultManager];\
if ([defaultManager isDeletableFileAtPath:YKDocumentFilePath(filename)]) {\
[defaultManager removeItemAtPath:YKDocumentFilePath(filename) error:nil];\
}\
}

/*** Notification ***/
#define YKSendNotification(name,sendObject,info) [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:name object:sendObject userInfo:info]];


#define YKLoadViewFromNib [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil] lastObject];
#define YKLoadViewFromNibWithIndex(index) [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil][index];

#define YKDeprecated(instead) __attribute__((deprecated(instead)))

#define YKNonnullString(str) ((str && [str isKindOfClass:[NSString class]] && str.length) ? str : @"")
#define YKNullableString(str) ((str && [str isKindOfClass:[NSString class]] && str.length) ? str : nil)

// 当前版本
#define YK_SYSTEM_VERSION          ([[[UIDevice currentDevice] systemVersion] floatValue])
#define YK_APP_NAME                ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"])
#define YK_APP_VERSION             ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"])
#define YK_APP_BUILD               ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"])
#define YK_APP_BUNDLE_ID           ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"])

/*** 错误 ***/
#define YKDomain YK_APP_BUNDLE_ID

#define YKError(errorMessage) [NSError errorWithDomain:YKDomain code:-1 userInfo:@{NSLocalizedDescriptionKey:errorMessage}]

#define YKError_(errorMessage,errorCode) [NSError errorWithDomain:YKDomain code:errorCode userInfo:@{NSLocalizedDescriptionKey:errorMessage}]

// 当前语言
#define YKCURRENTLANGUAGE         ([[NSLocale preferredLanguages] objectAtIndex:0])



#endif /* YKConst_h */

